package com.huike.web.controller.report;



import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.vo.ActivityStatisticsListVo;
import com.huike.report.domain.vo.ActivityStatisticsPageVo;
import com.huike.report.domain.vo.ChanelStatisticsVo;
import com.huike.report.domain.vo.LineChartVO;
import com.huike.report.service.IReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController extends BaseController {
    @Autowired
    private IReportService iReportService;

    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO NewReport(@PathVariable String beginCreateTime,
                                 @PathVariable String endCreateTime

    ) throws ParseException {

        LineChartVO lineChartVO=iReportService.NewReport(beginCreateTime,endCreateTime);
        return lineChartVO;
    }
    /**
     * 漏斗图接口开发
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult tongji(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return AjaxResult.success(iReportService.getVulnerabilityMap(beginCreateTime, endCreateTime));
    }

    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public List<ChanelStatisticsVo> chanelStatistics(@PathVariable  String beginCreateTime,
                                                     @PathVariable  String endCreateTime){
        List<ChanelStatisticsVo> chanelStatisticsVoList = iReportService.chanelStatistics(beginCreateTime,endCreateTime);
        return chanelStatisticsVoList;
    }

    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public List<ActivityStatisticsListVo> activityStatistics(@PathVariable String beginCreateTime,
                                                             @PathVariable String endCreateTime){
      List<ActivityStatisticsListVo> list = iReportService.activityStatistics(beginCreateTime,endCreateTime);
        return list;
    }

    @GetMapping("/activityStatisticsList")
    public TableDataInfo activityStatisticsList(String beginCreateTime, String endCreateTime,
                                                String code, String name,
                                                @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        ActivityStatisticsPageVo activityStatisticsVo = iReportService.activityStatisticsList(beginCreateTime,endCreateTime,
                code,name,pageNum,pageSize);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(activityStatisticsVo.getRows());
        tableDataInfo.setTotal(activityStatisticsVo.getTotal());
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;
    }



    @GetMapping("/cluesStatisticsList")
    public TableDataInfo CountSelect(Integer pageNum, Integer pageSize, String beginCreateTime, String endCreateTime){
        TableDataInfo tableDataInfo=iReportService.CountSelect(pageNum,pageSize,beginCreateTime,endCreateTime);
        return tableDataInfo;
    }


    /**
     * 客户统计时间列表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO selectAllClient(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) throws ParseException {
   LineChartVO lineChartVO=   iReportService.selectAllClient(beginCreateTime,endCreateTime);
   return  lineChartVO;
    }


    /**
     * 销售统计时间列表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     * @throws ParseException
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO saleStatistics(@PathVariable String beginCreateTime,
                                      @PathVariable String endCreateTime) throws ParseException {
        LineChartVO lineChartVO = iReportService.saleStatistics(beginCreateTime,endCreateTime);
        return lineChartVO;
    }

    /**
     * 销售统计报表--归属部门
     * @param pageNum
     * @param pageSize
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/deptStatisticsList/{begin}/{end}")
    public TableDataInfo deptStatisticsList(Integer pageNum, Integer pageSize,
                                            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        TableDataInfo tableDataInfo = iReportService.deptStatisticsList(pageNum,pageSize,begin,end);
        return tableDataInfo;
    }
//    @DateTime(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    /**
     * 销售统计报表--归属人
     * @param pageNum
     * @param pageSize
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{begin}/{end}")
    public TableDataInfo ownerShipStatisticsList(Integer pageNum,Integer pageSize,
                                                 @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate begin,
                                                 @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate end){
        TableDataInfo tableDataInfo = iReportService.ownerShipStatisticsList(pageNum,pageSize,begin,end);
        return tableDataInfo;
    }

    /**
     * 销售统计报表--归属渠道
     * @param pageNum
     * @param pageSize
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/channelStatisticsList/{begin}/{end}")
    public TableDataInfo channelStatisticsList(Integer pageNum,Integer pageSize,
                                               @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate begin,
                                               @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate end){
        TableDataInfo tableDataInfo = iReportService.channelStatisticsList(pageNum,pageSize,begin,end);
        return tableDataInfo;
    }


    /**
     * 客户分页查询
     * @param contract
     * @return
     */
    @GetMapping("/contractStatisticsList")
    public  TableDataInfo contractStatisticsList(TbContract contract){
        //请求分页
        startPage();
 List<TbContract> tbContractList=iReportService.contractStatisticsList(contract);
 //闯入分页数据
        //getDataTable需要传入的参数是一个集合
    TableDataInfo tableDataInfo =    getDataTable(tbContractList);
    return tableDataInfo;

    }
//
    /**
     * 学科客户分布
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public List subjectStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        List list=iReportService.subject(beginCreateTime,endCreateTime);
        return list;
    }

}
